package com.shxzz.shortlink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shxzz.shortlink.admin.common.convention.result.Result;
import com.shxzz.shortlink.admin.remote.LinkRemoteService;
import com.shxzz.shortlink.admin.remote.dto.req.RecycleBinPageReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.RecycleBinRemoveReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.RecycleBinRestoreReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.RecycleBinSaveReqDTO;
import com.shxzz.shortlink.admin.remote.dto.resp.RecycleBinLinkPageRespDTO;
import com.shxzz.shortlink.admin.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shxzz
 * @create 2023-12-25-19:55
 * @description 用户回收站管理控制层
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;

    /**
     * 后续重构为 SpringCloud Feign 调用
     */
    LinkRemoteService shortLinkRemoteService = new LinkRemoteService() {
    };

    /**
     * 保存回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        return shortLinkRemoteService.moveToRecycleBin(requestParam);
    }

    /**
     * 分页查询回收站短链接
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<IPage<RecycleBinLinkPageRespDTO>> pageShortLink(RecycleBinPageReqDTO requestParam) {
        return recycleBinService.selectPageRecycleBin(requestParam);
    }

    /**
     * 恢复短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> restoreRecycleBinLink(@RequestBody RecycleBinRestoreReqDTO requestParam) {
        return shortLinkRemoteService.restoreRecycleBinLink(requestParam);
    }

    /**
     * 移除短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveReqDTO requestParam) {
        return shortLinkRemoteService.removeRecycleBinLink(requestParam);
    }
}
